<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>心理测试 - 小笑舒压</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            color: #333;
        }

        .container {
            max-width: 414px;
            margin: 0 auto;
            background: #fff;
            min-height: 100vh;
            position: relative;
        }

        .top-nav {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 15px 20px;
            display: flex;
            align-items: center;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .back-btn {
            background: none;
            border: none;
            color: white;
            font-size: 18px;
            cursor: pointer;
            margin-right: 15px;
        }

        .page-title {
            font-size: 18px;
            font-weight: 600;
        }

        .progress-section {
            background: white;
            padding: 20px;
            border-bottom: 1px solid #eee;
        }

        .progress-info {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }

        .progress-text {
            font-size: 14px;
            color: #666;
        }

        .progress-bar {
            width: 100%;
            height: 8px;
            background: #f0f0f0;
            border-radius: 4px;
            overflow: hidden;
        }

        .progress-fill {
            height: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 4px;
            transition: width 0.3s ease;
        }

        .question-section {
            padding: 20px;
            min-height: 400px;
        }

        .question-card {
            background: white;
            border-radius: 16px;
            padding: 25px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            margin-bottom: 20px;
        }

        .question-number {
            font-size: 14px;
            color: #667eea;
            margin-bottom: 15px;
            font-weight: 500;
        }

        .question-text {
            font-size: 18px;
            line-height: 1.6;
            margin-bottom: 25px;
            color: #333;
            font-weight: 500;
        }

        .options {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .option {
            padding: 15px 20px;
            border: 2px solid #e0e0e0;
            border-radius: 12px;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            background: white;
        }

        .option:hover {
            border-color: #667eea;
            background: #f8f9ff;
        }

        .option.selected {
            border-color: #667eea;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

        .option-label {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background: #667eea;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 600;
            margin-right: 15px;
            flex-shrink: 0;
        }

        .option.selected .option-label {
            background: white;
            color: #667eea;
        }

        .option-text {
            flex: 1;
            font-size: 16px;
        }

        .button-section {
            padding: 20px;
            position: sticky;
            bottom: 0;
            background: white;
            border-top: 1px solid #eee;
        }

        .btn {
            width: 100%;
            padding: 15px;
            border: none;
            border-radius: 12px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
        }

        .btn-primary:disabled {
            background: #ccc;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }

        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            display: none;
            align-items: center;
            justify-content: center;
            z-index: 1000;
        }

        .modal {
            background: white;
            border-radius: 20px;
            padding: 30px;
            max-width: 350px;
            width: 90%;
            text-align: center;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            animation: modalSlideIn 0.3s ease;
        }

        @keyframes modalSlideIn {
            from {
                opacity: 0;
                transform: translateY(-50px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .result-icon {
            font-size: 60px;
            margin-bottom: 20px;
        }

        .result-title {
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 15px;
            color: #333;
        }

        .pressure-score {
            font-size: 36px;
            font-weight: 700;
            color: #667eea;
            margin-bottom: 15px;
        }

        .result-description {
            font-size: 16px;
            line-height: 1.6;
            color: #666;
            margin-bottom: 25px;
        }

        .modal-btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 30px;
            border-radius: 25px;
            font-size: 16px;
            cursor: pointer;
            transition: transform 0.3s ease;
        }

        .modal-btn:hover {
            transform: translateY(-2px);
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="top-nav">
            <button class="back-btn" onclick="goBack()">
                <i class="fas fa-arrow-left"></i>
            </button>
            <div class="page-title">心理压力测试</div>
        </div>

        <div class="progress-section">
            <div class="progress-info">
                <span class="progress-text">测试进度</span>
                <span class="progress-text" id="progressText">1/10</span>
            </div>
            <div class="progress-bar">
                <div class="progress-fill" id="progressFill" style="width: 10%"></div>
            </div>
        </div>

        <div class="question-section" id="questionSection">
        </div>

        <div class="button-section">
            <button class="btn btn-primary" id="nextBtn" onclick="nextQuestion()" disabled>
                下一题
            </button>
        </div>
    </div>

    <div class="modal-overlay" id="resultModal">
        <div class="modal">
            <div class="result-icon" id="resultIcon">😊</div>
            <div class="result-title" id="resultTitle">测试完成</div>
            <div class="pressure-score" id="pressureScore">0</div>
            <div class="result-description" id="resultDescription">
                根据您的选择，我们分析了您的心理压力状况
            </div>
            <button class="modal-btn" onclick="closeModal()">知道了</button>
        </div>
    </div>

    <script>
        const allQuestions = [
            "您是否经常感到焦虑不安？",
            "您是否容易因为小事而发脾气？",
            "您是否经常失眠或睡眠质量差？",
            "您是否感到工作压力很大？",
            "您是否经常感到疲惫无力？",
            "您是否容易紧张和担心？",
            "您是否经常感到心情低落？",
            "您是否容易感到孤独？",
            "您是否经常感到时间不够用？",
            "您是否容易感到挫败感？",
            "您是否经常感到身体不适？",
            "您是否容易感到烦躁？",
            "您是否经常感到注意力不集中？",
            "您是否容易感到自卑？",
            "您是否经常感到胃部不适？",
            "您是否容易感到恐惧？",
            "您是否经常感到记忆力下降？",
            "您是否容易感到愤怒？",
            "您是否经常感到胸闷气短？",
            "您是否容易感到绝望？",
            "您是否经常感到头痛？",
            "您是否容易感到内疚？",
            "您是否经常感到肌肉紧张？",
            "您是否容易感到羞耻？",
            "您是否经常感到心跳加快？",
            "您是否容易感到无助？",
            "您是否经常感到出汗过多？",
            "您是否容易感到嫉妒？",
            "您是否经常感到食欲不振？",
            "您是否容易感到怨恨？"
        ];

        let currentQuestionIndex = 0;
        let selectedQuestions = [];
        let userAnswers = [];
        let currentAnswer = null;

        document.addEventListener('DOMContentLoaded', function () {
            selectedQuestions = getRandomQuestions(allQuestions, 10);
            showQuestion();
        });

        function getRandomQuestions(questions, count) {
            const shuffled = [...questions].sort(() => 0.5 - Math.random());
            return shuffled.slice(0, count);
        }

        function showQuestion() {
            const questionSection = document.getElementById('questionSection');
            const question = selectedQuestions[currentQuestionIndex];

            questionSection.innerHTML = `
                <div class="question-card">
                    <div class="question-number">第 ${currentQuestionIndex + 1} 题</div>
                    <div class="question-text">${question}</div>
                    <div class="options">
                        <div class="option" onclick="selectOption('A', this)">
                            <div class="option-label">A</div>
                            <div class="option-text">从不</div>
                        </div>
                        <div class="option" onclick="selectOption('B', this)">
                            <div class="option-label">B</div>
                            <div class="option-text">偶尔</div>
                        </div>
                        <div class="option" onclick="selectOption('C', this)">
                            <div class="option-label">C</div>
                            <div class="option-text">经常</div>
                        </div>
                        <div class="option" onclick="selectOption('D', this)">
                            <div class="option-label">D</div>
                            <div class="option-text">总是</div>
                        </div>
                    </div>
                </div>
            `;

            updateProgress();
            currentAnswer = null;
            document.getElementById('nextBtn').disabled = true;
        }

        function selectOption(answer, element) {
            document.querySelectorAll('.option').forEach(opt => {
                opt.classList.remove('selected');
            });

            element.classList.add('selected');
            currentAnswer = answer;
            document.getElementById('nextBtn').disabled = false;
        }

        function nextQuestion() {
            if (currentAnswer === null) return;

            userAnswers.push(currentAnswer);

            if (currentQuestionIndex < selectedQuestions.length - 1) {
                currentQuestionIndex++;
                showQuestion();
            } else {
                showResult();
            }
        }

        function updateProgress() {
            const progress = ((currentQuestionIndex + 1) / selectedQuestions.length) * 100;
            document.getElementById('progressFill').style.width = progress + '%';
            document.getElementById('progressText').textContent = `${currentQuestionIndex + 1}/${selectedQuestions.length}`;
        }

        function showResult() {
            const score = calculatePressureScore();
            const result = getPressureResult(score);

            document.getElementById('pressureScore').textContent = score;
            document.getElementById('resultTitle').textContent = result.title;
            document.getElementById('resultDescription').textContent = result.description;
            document.getElementById('resultIcon').textContent = result.icon;

            document.getElementById('resultModal').style.display = 'flex';
        }

        function calculatePressureScore() {
            let score = 0;
            userAnswers.forEach(answer => {
                switch (answer) {
                    case 'A': score += 1; break;
                    case 'B': score += 2; break;
                    case 'C': score += 3; break;
                    case 'D': score += 4; break;
                }
            });

            return Math.round((score / (selectedQuestions.length * 4)) * 100);
        }

        function getPressureResult(score) {
            if (score <= 25) {
                return {
                    title: "压力指数较低",
                    description: "恭喜！您的心理压力状况良好，继续保持积极乐观的心态。",
                    icon: "😊"
                };
            } else if (score <= 50) {
                return {
                    title: "压力指数中等",
                    description: "您的压力水平适中，建议适当放松，保持工作生活平衡。",
                    icon: "😌"
                };
            } else if (score <= 75) {
                return {
                    title: "压力指数较高",
                    description: "您当前压力较大，建议寻求专业帮助，学会调节情绪。",
                    icon: "😐"
                };
            } else {
                return {
                    title: "压力指数很高",
                    description: "您的压力水平很高，强烈建议咨询专业心理咨询师。",
                    icon: "😔"
                };
            }
        }

        function closeModal() {
            document.getElementById('resultModal').style.display = 'none';
        }

        function goBack() {
            window.location.href = 'index.html';
        }
    </script>
</body>

</html>